
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="wk wk-my-task icon" />
        </div>
        <span class="text">客户城市分布分析</span>
      </div>
    </div>

    <div class="content">
      <a-row :span="24">
        <a-col :span="12"
          ><div class="axis-content">
            <div id="allChart" class="axismain" /></div
        ></a-col>
        <a-col :span="12"
          ><div class="axis-content">
            <div id="dealChart" class="axismain" /></div
        ></a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
import { postAction, downFile } from '@/api/manage'
import 'echarts/map/js/china.js'
export default {
  /** 客户总量分析 */
  name: 'CustomerTotalStatistics',
  data() {
    return {
       reportId: '',
      reportTitle: '',
      loading: false,
      allOption: null,
      dealOption: null,
      chartObj: null,
      chartOtherObj: null,
       keyList: [],
      valueList: [],
      url: {
        executeGraphReport: '/online/api/executeGraphReport',
        exportXlsUrl: '/online/api/export/exportXlsGraphReport',
      },
    }
  },

  mounted() {
    this.initAxis()
    this.getDataList()
  },
  methods: {
    async  getDataList(params) {
     this.reportId = 'customerProvinceNum';
      const res = await  postAction(this.url.executeGraphReport, { id: this.reportId });
     
       this.keyList=res.result.chartDataList;


 this.keyList.forEach((item, index) => {
        this.valueList.push({ address: item[0], allCustomer: item[1], dealCustomer: item[2] })
      })
      let result1 = [
        { allCustomer: 0, address: '北京', dealCustomer: null },
        { allCustomer: 0, address: '上海', dealCustomer: null },
        { allCustomer: 0, address: '天津', dealCustomer: null },
        { allCustomer: 0, address: '广东', dealCustomer: null },
        { allCustomer: 0, address: '浙江', dealCustomer: null },
        { allCustomer: 0, address: '海南', dealCustomer: null },
        { allCustomer: 0, address: '福建', dealCustomer: null },
        { allCustomer: 0, address: '湖南', dealCustomer: null },
        { allCustomer: 0, address: '湖北', dealCustomer: null },
        { allCustomer: 0, address: '重庆', dealCustomer: null },
        { allCustomer: 0, address: '辽宁', dealCustomer: null },
        { allCustomer: 0, address: '吉林', dealCustomer: null },
        { allCustomer: 0, address: '黑龙江', dealCustomer: null },
        { allCustomer: 0, address: '河南', dealCustomer: null },
        { allCustomer: 0, address: '河北', dealCustomer: null },
        { allCustomer: 0, address: '陕西', dealCustomer: null },
        { allCustomer: 0, address: '甘肃', dealCustomer: null },
        { allCustomer: 0, address: '宁夏', dealCustomer: null },
        { allCustomer: 0, address: '西藏', dealCustomer: null },
        { allCustomer: 0, address: '新疆', dealCustomer: null },
        { allCustomer: 0, address: '青海', dealCustomer: null },
        { allCustomer: 0, address: '四川', dealCustomer: null },
        { allCustomer: 0, address: '广西', dealCustomer: null },
        { allCustomer: 0, address: '贵州', dealCustomer: null },
        { allCustomer: 0, address: '江西', dealCustomer: null },
        { allCustomer: 0, address: '江苏', dealCustomer: null },
        { allCustomer: 0, address: '云南', dealCustomer: null },
        { allCustomer: 0, address: '内蒙古', dealCustomer: null },
        { allCustomer: 0, address: '山东', dealCustomer: null },
        { allCustomer: 0, address: '山西', dealCustomer: null },
        { allCustomer: 0, address: '安徽', dealCustomer: null },
      ]
      let result =this.valueList;
console.log(result);
      const allData = []
      const dealData = []
      for (let index = 0; index < result.length; index++) {
        const element = result[index]
        if (element.allCustomer) {
          allData.push({
            name: element.address,
            value: element.allCustomer,
          })
        }

        if (element.dealCustomer) {
          dealData.push({
            name: element.address,
            value: element.dealCustomer,
          })
        }
      }

      this.allOption.series[0].data = allData
      this.dealOption.series[0].data = dealData
      this.chartObj.setOption(this.allOption, true)
      this.chartOtherObj.setOption(this.dealOption, true)
    },
    /** 柱状图 */
    initAxis() {
      this.chartObj = this.echarts.init(document.getElementById('allChart'))
      this.chartOtherObj = this.echarts.init(document.getElementById('dealChart'))
      this.allOption = this.getChartOptione('全部客户')
      this.dealOption = this.getChartOptione('成交客户')
      this.chartObj.setOption(this.allOption, true)
      this.chartOtherObj.setOption(this.dealOption, true)
    },
    getChartOptione(title) {
      return {
        title: {
          text: title,
          left: 'center',
          bottom: 0,
        },
        tooltip: {
          trigger: 'item',
          formatter: function (data) {
            if (data.value) {
              return data.name + '<br/>' + (data.value || '-') + '（个）'
            }
          },
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ['客户数'],
        },
        visualMap: {
          min: 0,
          max: 50,
          left: 'left',
          top: 'bottom',
          text: ['多', '少'], // 文本，默认为数值文本
          calculable: true,
          inRange: {
            color: ['lightskyblue', 'yellow', 'orangered'],
          },
        },
        toolbox: {
          show: true,
          orient: 'vertical',
          left: 'right',
          top: 'center',
          feature: {
            mark: { show: true },
            dataView: {
              show: true,
              readOnly: false,
              optionToContent: function (opt) {
                var data = opt.series[0].data
                var table =
                  '<table style="width:100%;text-align:center"><tbody><tr>' +
                  '<td>城市</td>' +
                  '<td>客户数</td>' +
                  '</tr>'
                for (var i = 0, l = data.length; i < l; i++) {
                  table += '<tr>' + '<td>' + data[i].name + '</td>' + '<td>' + data[i].value + '</td>' + '</tr>'
                }
                table += '</tbody></table>'
                return table
              },
            },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        series: [
          {
            name: '',
            type: 'map',
            mapType: 'china',
            showLegendSymbol: false,
            itemStyle: {
              normal: { label: { show: true }, borderColor: '#ccc' },
              emphasis: { label: { show: true } },
            },
            data: [],
          },
        ],
      }
    },

    /**
     * 导出点击
     */
    exportClick() {},
  },
}
</script>


<style lang="less" scoped>
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #168a40;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

.content {
  height: calc(100% - 54px);
  overflow-y: auto;
  padding: 10px 0;
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #axismain {
    margin: 0 auto;
    width: 100%;
    height: 400px;
  }
}

.table-content {
  padding: 0 60px 20px 60px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
/deep/ .ant-table-wrapper {
  height: 400px;
  border: 1px solid #ebeef5;
}
/deep/ .ant-table-placeholder {
  display: none;
}
</style>

